package com.shunda.ysdgj.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "业务响应实体")
public class ResultVo<T> {
    @Schema(description = "业务状态码")
    private Integer code;

    @Schema(description = "响应消息")
    private String message;

    @Schema(description = "业务数据")
    private T data;

    private ResultVo() {}

    public static <T> ResultVo<T> build(Integer code, String message, T data) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> ResultVo<T> build(Integer code, String message) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static <T> ResultVo<T> build(ResultCodeEnum resultCode) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        result.setData(null);
        return result;
    }

    public static <T> ResultVo<T> build(ResultCodeEnum resultCode, T data) {
        ResultVo<T> result = new ResultVo<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> ResultVo<T> success() {
        return build(ResultCodeEnum.SUCCESS, null);
    }

    public static <T> ResultVo<T> success(T data) {
        return build(ResultCodeEnum.SUCCESS, data);
    }

    public static<T> ResultVo<T> fail() {
        return build(ResultCodeEnum.FAIL, null);
    }
}
